package model;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;


public class Block extends GameObject
{
	protected boolean breakable;
	protected boolean visible;
	protected int hitCount;
	protected int hitLimit;
	
	public Block()
	{
		super();
		xDim = 60;
		yDim = 15;
		breakable = false;
		visible = true;
		hitCount = 0;
		hitLimit = -1;
		color = Color.BLACK;
	}
	
	public Block(int hitLimit)
	{
		super();
		xDim = 60;
		yDim = 15;
		breakable = (hitLimit > 0);
		visible = true;
		hitCount = 0;
		color = Color.BLACK;
		this.hitLimit = hitLimit;
	}
	
	public Block(int xDim, int yDim, String filename, Vector2 v)
	{
		super(xDim, yDim, filename, v, false);
		this.xDim = 60;
		yDim = 15;
		breakable = false;
		visible = true;
		hitCount = 0;
		hitLimit = -1;
	}
	
	public Block(Block block)
	{
		super(block.getDimX(), block.getDimY(), block.getFilename(), block.getVect(), false);
		breakable = block.isBreakable();
		visible = block.isVisible();
		hitCount = block.getHitCount();
		hitLimit = block.getLimit();
		
		filename = block.getFilename();
		
		try{
			image = ImageIO.read(new File(filename));
		} catch(IOException e){	
		}
	}
	
	public void gotHit()
	{
		hitCount++;
		
		if(hitLimit > 0)
			hitLimit--;
		
		if(hitLimit == 0)
			visible = false;
	}
	
	public boolean isBreakable()
	{
		return breakable;
	}
	
	public int getLimit()
	{
		return hitLimit;
	}
	
	public boolean isVisible()
	{
		return visible;
	}
	
	public int getHitCount()
	{
		return hitCount;
	}
	
	public void draw(Graphics page)
	{
		if(visible)
			page.drawImage(image, (int)getX(), (int)getY(), null);
	}
	
	
}
